<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.7"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>qLibc: ipc/qshm.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">qLibc
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.7 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',false,false,'search.php','Search');
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('qshm_8c.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle"><div class="title">qshm.c File Reference</div></div>
</div><!--header-->
<div class="contents">

<p>Shared-memory APIs.  
<a href="#details">More...</a></p>

<p><a href="qshm_8c_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a881b11a2d26ae83230151955545630ed"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qshm_8c.html#a881b11a2d26ae83230151955545630ed">qshm_init</a> (const char *keyfile, int keyid, size_t size, bool recreate)</td></tr>
<tr class="memdesc:a881b11a2d26ae83230151955545630ed"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialize shared-memory.  <br /></td></tr>
<tr class="separator:a881b11a2d26ae83230151955545630ed"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa6b1f31987b42fe18dc6be25e58c0bce"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qshm_8c.html#aa6b1f31987b42fe18dc6be25e58c0bce">qshm_getid</a> (const char *keyfile, int keyid)</td></tr>
<tr class="memdesc:aa6b1f31987b42fe18dc6be25e58c0bce"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get shared memory identifier by keyfile and keyid for existing shared memory.  <br /></td></tr>
<tr class="separator:aa6b1f31987b42fe18dc6be25e58c0bce"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a04d0a8cb2c672f568931132d0c1b5246"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qshm_8c.html#a04d0a8cb2c672f568931132d0c1b5246">qshm_get</a> (int shmid)</td></tr>
<tr class="memdesc:a04d0a8cb2c672f568931132d0c1b5246"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get a pointer of shared memory.  <br /></td></tr>
<tr class="separator:a04d0a8cb2c672f568931132d0c1b5246"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aec816f3889e85322e0304c3cbd67c639"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qshm_8c.html#aec816f3889e85322e0304c3cbd67c639">qshm_free</a> (int shmid)</td></tr>
<tr class="memdesc:aec816f3889e85322e0304c3cbd67c639"><td class="mdescLeft">&#160;</td><td class="mdescRight">De-allocate shared memory.  <br /></td></tr>
<tr class="separator:aec816f3889e85322e0304c3cbd67c639"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Shared-memory APIs. </p>
<dl class="section note"><dt>Note</dt><dd><div class="fragment"><div class="line">[your header file]</div>
<div class="line"><span class="keyword">struct </span>SharedData {</div>
<div class="line">  (... structrue definitions ...)</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line">[shared memory creater]</div>
<div class="line"><span class="comment">// create shared memory</span></div>
<div class="line"><span class="keywordtype">int</span> shmid = <a class="code hl_function" href="qshm_8c.html#a881b11a2d26ae83230151955545630ed">qshm_init</a>(<span class="stringliteral">&quot;/some/file/for/generating/unique/key&quot;</span>, <span class="charliteral">&#39;s&#39;</span>, <span class="keyword">sizeof</span>(<span class="keyword">struct</span> SharedData), <span class="keyword">true</span>);</div>
<div class="line"><span class="keywordflow">if</span>(shmid &lt; 0) {</div>
<div class="line">  printf(<span class="stringliteral">&quot;ERROR: Can&#39;t initialize shared memory.\n&quot;</span>);</div>
<div class="line">  <span class="keywordflow">return</span> -1;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">// get shared memory pointer</span></div>
<div class="line"><span class="keyword">struct </span>SharedData *sdata = (SharedData *)<a class="code hl_function" href="qshm_8c.html#a04d0a8cb2c672f568931132d0c1b5246">qshm_get</a>(shmid);</div>
<div class="line"><span class="keywordflow">if</span>(sdata == NULL) {</div>
<div class="line">  printf(<span class="stringliteral">&quot;ERROR: Can&#39;t get shared memory.\n&quot;</span>);</div>
<div class="line">  <span class="keywordflow">return</span> -1;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line">[shared memory user]</div>
<div class="line"><span class="comment">// get shared memory id</span></div>
<div class="line"><span class="keywordtype">int</span> shmid = <a class="code hl_function" href="qshm_8c.html#aa6b1f31987b42fe18dc6be25e58c0bce">qshm_getid</a>(<span class="stringliteral">&quot;/some/file/for/generating/unique/key&quot;</span>, <span class="charliteral">&#39;s&#39;</span>);</div>
<div class="line"><span class="keywordflow">if</span>(shmid &lt; 0) {</div>
<div class="line">  printf(<span class="stringliteral">&quot;ERROR: Can&#39;t get shared memory id.\n&quot;</span>);</div>
<div class="line">  <span class="keywordflow">return</span> -1;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">// get shared memory pointer</span></div>
<div class="line"><span class="keyword">struct </span>SharedData *sdata = (SharedData *)<a class="code hl_function" href="qshm_8c.html#a04d0a8cb2c672f568931132d0c1b5246">qshm_get</a>(shmid);</div>
<div class="line"><span class="keywordflow">if</span>(sdata == NULL) {</div>
<div class="line">  printf(<span class="stringliteral">&quot;ERROR: Can&#39;t get shared memory.\n&quot;</span>);</div>
<div class="line">  <span class="keywordflow">return</span> -1;</div>
<div class="line">}</div>
<div class="ttc" id="aqshm_8c_html_a04d0a8cb2c672f568931132d0c1b5246"><div class="ttname"><a href="qshm_8c.html#a04d0a8cb2c672f568931132d0c1b5246">qshm_get</a></div><div class="ttdeci">void * qshm_get(int shmid)</div><div class="ttdoc">Get a pointer of shared memory.</div><div class="ttdef"><b>Definition</b> <a href="qshm_8c_source.html#l00149">qshm.c:149</a></div></div>
<div class="ttc" id="aqshm_8c_html_a881b11a2d26ae83230151955545630ed"><div class="ttname"><a href="qshm_8c.html#a881b11a2d26ae83230151955545630ed">qshm_init</a></div><div class="ttdeci">int qshm_init(const char *keyfile, int keyid, size_t size, bool recreate)</div><div class="ttdoc">Initialize shared-memory.</div><div class="ttdef"><b>Definition</b> <a href="qshm_8c_source.html#l00091">qshm.c:91</a></div></div>
<div class="ttc" id="aqshm_8c_html_aa6b1f31987b42fe18dc6be25e58c0bce"><div class="ttname"><a href="qshm_8c.html#aa6b1f31987b42fe18dc6be25e58c0bce">qshm_getid</a></div><div class="ttdeci">int qshm_getid(const char *keyfile, int keyid)</div><div class="ttdoc">Get shared memory identifier by keyfile and keyid for existing shared memory.</div><div class="ttdef"><b>Definition</b> <a href="qshm_8c_source.html#l00127">qshm.c:127</a></div></div>
</div><!-- fragment --> </dd></dl>

<p class="definition">Definition in file <a class="el" href="qshm_8c_source.html">qshm.c</a>.</p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a881b11a2d26ae83230151955545630ed" name="a881b11a2d26ae83230151955545630ed"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a881b11a2d26ae83230151955545630ed">&#9670;&#160;</a></span>qshm_init()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int qshm_init </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>keyfile</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>keyid</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>size</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>recreate</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialize shared-memory. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">keyfile</td><td>seed for generating unique IPC key </td></tr>
    <tr><td class="paramname">keyid</td><td>seed for generating unique IPC key </td></tr>
    <tr><td class="paramname">size</td><td>size of shared memory </td></tr>
    <tr><td class="paramname">recreate</td><td>set to true to re-create shared-memory if already exists</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>non-negative shared memory identifier if successful, otherwise returns -1 </dd></dl>

<p class="definition">Definition at line <a class="el" href="qshm_8c_source.html#l00091">91</a> of file <a class="el" href="qshm_8c_source.html">qshm.c</a>.</p>

</div>
</div>
<a id="aa6b1f31987b42fe18dc6be25e58c0bce" name="aa6b1f31987b42fe18dc6be25e58c0bce"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa6b1f31987b42fe18dc6be25e58c0bce">&#9670;&#160;</a></span>qshm_getid()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int qshm_getid </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>keyfile</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>keyid</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get shared memory identifier by keyfile and keyid for existing shared memory. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">keyfile</td><td>seed for generating unique IPC key </td></tr>
    <tr><td class="paramname">keyid</td><td>seed for generating unique IPC key</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>non-negative shared memory identifier if successful, otherwise returns -1 </dd></dl>

<p class="definition">Definition at line <a class="el" href="qshm_8c_source.html#l00127">127</a> of file <a class="el" href="qshm_8c_source.html">qshm.c</a>.</p>

</div>
</div>
<a id="a04d0a8cb2c672f568931132d0c1b5246" name="a04d0a8cb2c672f568931132d0c1b5246"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a04d0a8cb2c672f568931132d0c1b5246">&#9670;&#160;</a></span>qshm_get()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void * qshm_get </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>shmid</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get a pointer of shared memory. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">shmid</td><td>shared memory identifier</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a pointer of shared memory </dd></dl>

<p class="definition">Definition at line <a class="el" href="qshm_8c_source.html#l00149">149</a> of file <a class="el" href="qshm_8c_source.html">qshm.c</a>.</p>

</div>
</div>
<a id="aec816f3889e85322e0304c3cbd67c639" name="aec816f3889e85322e0304c3cbd67c639"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aec816f3889e85322e0304c3cbd67c639">&#9670;&#160;</a></span>qshm_free()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qshm_free </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>shmid</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>De-allocate shared memory. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">shmid</td><td>shared memory identifier</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise returns false </dd></dl>

<p class="definition">Definition at line <a class="el" href="qshm_8c_source.html#l00167">167</a> of file <a class="el" href="qshm_8c_source.html">qshm.c</a>.</p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_b94456e2763cc4ff61641ee1fd517631.html">ipc</a></li><li class="navelem"><a class="el" href="qshm_8c.html">qshm.c</a></li>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.7 </li>
  </ul>
</div>
</body>
</html>
